<template>
  <div>
    <VolBox :lazy="true" :model.sync="model" :title="'报名活动--' + title" :width="Mwidth" :height="Mheight">
      <VolForm ref="formRules1" :label-width="100" :loadKey="true" :formFields="formFields1" :formRules="formRules1"></VolForm>
      <VolForm v-if="
          formFields1.c_type === '0' ||
            formFields1.c_type === '1' ||
            formFields1.c_type === '8'
        " ref="myform2" :label-width="100" :loadKey="true" :formFields="formFields2" :formRules="formRules2">
      </VolForm>
      <VolForm v-if="formFields1.c_type === '1'" ref="myform3" :label-width="100" :loadKey="true" :formFields="formFields3" :formRules="formRules3"></VolForm>
      <div v-else-if="formFields1.c_type === '2' || formFields1.c_type === '3'">
        <VolForm ref="myform4" :label-width="100" :loadKey="true" :formFields="formFields4" :formRules="formRules4"></VolForm>
        <el-form label-width="100px" :disabled="disabledformFields4" class="formFields5">
          <el-form-item label="优惠条件" class="ivu-form-item-label">
            <div class="yhtjint" v-for="(i, ii) in formlist" :key="ii">
              <span>消费满</span>
              <el-input size="small" v-model="i.fullPrice"></el-input>
              <span style="margin-left:10px">{{ listType }}</span>
              <el-input size="small" v-model="i.discount"></el-input>
              <el-button size="small" v-if="ii == 0" @click="btnClick(1, ii)" :disabled="buttonDisabled">+</el-button>
              <el-button size="small" v-else @click="btnClick(0, ii)" :disabled="buttonDisabled">-</el-button>
            </div>
          </el-form-item>
        </el-form>
      </div>
      <div class="from_table_box">
        <div class="header_box">
          <div class="tab"></div>
          <div class="button_box">
            <div class="el-icon-plus button_item" @click="
                () => {
                  this.$refs.table_one.addRow();
                }
              ">
              &nbsp;添加行
            </div>
            <div class="el-icon-close button_item" @click="delRows()">
              &nbsp;删除行
            </div>
          </div>
        </div>
        <div class="table_box">
          <vol-table ref="table_one" :loadKey="true" :columns="rechargeGift" :height="210" :defaultLoadPage="false" :row-index="true" :columnIndex="true" :index="true"
            :click-edit="true" :tableData="tableData" :paginationHide="true"></vol-table>
        </div>
        <vol-box :model.sync="box1" title="选择券或券包" :height="600" :width="1000" :padding="15">
          <div class="button_box">
            <div class="el-icon-plus button_item" @click="btnClick(table_one)">
              &nbsp;添加
            </div>
            <div class="el-icon-close button_item" @click="
                () => {
                  this.$refs.table_two.delRows();
                }
              ">
              &nbsp;删除行
            </div>
          </div>
          <vol-table ref="table_two" :loadKey="true" :columns="columnsTicket" :pagination-hide="false" :height="510" :columnIndex="false" :index="true" :click-edit="true"
            :tableData="ticketTableData" :paginationHide="true" :summary="true"></vol-table>
          <el-button v-show="title != '查看' && ActivityTypeStatus" class="boxButton" :disabled="buttonDisabled" @click="addsp">商品选择</el-button>
          <vol-table ref="octable" :loadKey="true" :columns="
              title == '新增' ? columns : buttonDisabled ? columnsc : columns
            " :tableData="goodsListInfo" :height="300" :summary="true" :columnIndex="true" :click-edit="true" :ck="false"></vol-table>
          <div slot="footer">
            <Button type="primary" @click="closeChild()">确认</Button>
          </div>
        </vol-box>
      </div>
      <div slot="footer">
        <Button type="error" icon="md-checkmark" v-show="title != '查看'" @click="submit1">确认</Button>
        <Button type="info" icon="md-clos" @click="model = false">关闭</Button>
      </div>
    </VolBox>
    <div></div>
    <VolBox :lazy="true" :model.sync="model2" title="商品选择" :width="Mwidth" :height="Mheight">
      <div class="SPXZ">
        <el-tree ref="tree" :data="CodityClaifa" show-checkbox node-key="id" :props="defaultProps" @check="checkchange">
        </el-tree>
        <el-select v-model="NameListDG" placeholder="请选择" @change="changeNameListDG" clearable>
          <el-option v-for="item in NameList" :key="item.key" :label="item.value" :value="item.key">
          </el-option>
        </el-select>
        <!-- NameList -->
        <div class="volTable">
          <el-input class="int" v-model="name" placeholder="请输入商品名称" @keyup.enter.native="checkchange"></el-input>
          <vol-table ref="xztable" :loadKey="true" :columns="columns2" :tableData="goodsListInfo2" :height="430" :summary="true" :columnIndex="true" :click-edit="true"></vol-table>
        </div>
      </div>

      <div slot="footer">
        <Button type="error" icon="md-checkmark" @click="submit2">保存</Button>
        <Button type="info" icon="md-close" @click="model2 = false">关闭</Button>
      </div>
    </VolBox>
    <vol-box :model.sync="box2" title="编辑" :height="500" :width="1000" :padding="15">
      <div class="cascader">
        <div class="casd">
          <el-button class="boxButton" @click="addsp">商品选择</el-button>
          <vol-table ref="octable" :loadKey="true" :columns="
              title == '新增' ? columns : buttonDisabled ? columnsc : columns
            " :tableData="goodsListInfo" :height="300" :summary="true" :columnIndex="true" :click-edit="true" :ck="false"></vol-table>
        </div>
      </div>
      <div slot="footer">
        <Button type="default" @click="voucherChild()">确认</Button>
      </div>
    </vol-box>
    <vol-box :model.sync="box3" title="选择券" :height="500" :width="600" :padding="15">
      <vol-table ref="Qtable" :loadKey="true" :columns="columns3" :tableData="voucherPackageList" :height="430" :summary="true" :columnIndex="true" :click-edit="true"></vol-table>
      <div slot="footer">
        <Button type="default" @click="voucherChilds()">确认</Button>
      </div>
    </vol-box>
    <vol-box :model.sync="box4" title=" 查看人员" :height="500" :width="800" :padding="15">
      <export-excel :name="tableName" domName="exportExcel"></export-excel>
      <el-table style="width: 100%" border :data="headerNameList" id="exportExcel">
        <el-table-column type="index" width="40"> </el-table-column>
        <template v-for="(item, index) in headerName">
          <el-table-column :prop="item.field" :label="item.title" :key="index" v-if="item.title != 'id'"></el-table-column>
        </template>
      </el-table>
      <div slot="footer">
        <Button type="default" @click="
            () => {
              this.box4 = false;
            }
          ">关闭</Button>
      </div>
    </vol-box>
    <vol-box :model.sync="box5" title="查看表单" :height="500" :width="800" :padding="15">
      <vol-table ref="headerNametables" :loadKey="true" :columns="headerNames" :tableData="headerNameLists" :height="800" :summary="true" :columnIndex="true"
        :click-edit="true"></vol-table>
      <div slot="footer">
        <Button type="default" @click="
            () => {
              this.box5 = false;
            }
          ">关闭</Button>
      </div>
    </vol-box>
  </div>
</template>
<script>
import VolBox from '@/components/basic/VolBox.vue'
import VolForm from '@/components/basic/VolForm.vue'
import VolTable from '@/components/basic/VolTable.vue'
import Icons from '@/components/basic/Icons.vue'

var vueParam = {
  components: {
    VolBox,
    VolForm,
    VolTable,
    Icons,
    ExportExcel: () => import('@/components/basic/ExportExcel.vue'),
  },
  data() {
    return {
      tableName: '人员',
      activeId: '',
      headerNameList: [],
      headerName: [],
      headerNameLists: [],
      headerNames: [
        {
          field: 'id',
          title: '表单Id',
          type: 'text',
          width: 180,
          align: 'left',
        },
        {
          field: 'form_name',
          title: '表单名称',
          width: 180,
          type: 'text',
        },
        {
          field: ' ',
          title: '操作',
          width: 150,
          formatter: () => {
            return "<div  class='oper-btn'>查看</div>"
          },
          click: (row, column, event) => {
            this.box4 = true
            this.http
              .post('api/Form/GetFormActivityIdJson', {
                formid: row.id,
                activeId: this.activeId,
              })
              .then((res) => {
                let headerName = []
                JSON.parse(res.data[0]).forEach((item) => {
                  if (item.type == 'p') {
                    headerName.push({
                      field: item.id,
                      title: item.text,
                      type: 'string',
                      align: 'center',
                    })
                  } else {
                    headerName.push({
                      field: item.id,
                      title: item.name,
                      type: 'string',
                      align: 'center',
                    })
                  }
                })
                console.log(headerName, 'headerName')
                this.headerName = headerName
                // 表头的数据内容
                let headerNameListobj = []
                res.data.forEach((element) => {
                  let headerNameList = []
                  if (element != '') {
                    JSON.parse(element).map(function (e, item) {
                      if (e.type != 'p') {
                        headerNameList[e.id] = e.value == '' ? '' : e.value
                      } else {
                        headerNameList[e.id] = e.text == '' ? '' : e.text
                      }
                    })
                    headerNameListobj.push(Object.assign({}, headerNameList))
                  }
                })
                this.headerNameList = headerNameListobj
                console.log(this.headerNameList, 'this.headerNameList')
              })
          },
        },
      ],
      goodListDel: [],
      skuList: [],
      productsList: [],
      checkList: [],
      memberphones: [],
      titles: ['待选名单', '已选名单'],
      kaAccount: [],
      applicabilityDisabled: true,
      kaList: [],
      radio: '1',
      elementIdex: '',
      model: false,
      box1: false,
      box2: false,
      box3: false,
      box4: false,
      box5: false,
      Mwidth: 1000,
      Mheight: 500,
      voucherPackageData: [],
      voucherPackageDataName: [],
      voucherPackageList: [],
      voucherPackageListGL: [],
      NameList: [],
      NameListDG: '',
      // 活动类型状态
      tableData: [],
      tableDatabefore: [],
      // 充值赠送
      rechargeGift: [
        {
          field: 'activity_session',
          title: '场次',
          type: 'select',
          width: 180,
          align: 'left',
          edit: { type: 'text' },
        },
        {
          field: 'activity_session_date',
          title: '场次时间',
          type: 'select',
          width: 180,
          align: 'left',
          type: 'datetimerange',
          edit: { type: 'datetimerange' },
        },
        {
          field: 'children',
          title: '场次备注',
          type: 'decimal',
          width: 90,
          align: 'left',
          edit: { type: 'text' },
          hidden: true,
        },
        {
          field: 'Render',
          title: '操作',
          fixed: 'right',
          width: 120,
          render: this.getRenderOperate(),
        },
      ],
      columnsTicket: [
        {
          field: 'id',
          title: '产品ID',
          type: 'string',
          width: 120,
          align: 'left',
          hidden: true,
          require: true,
        },
        {
          field: 'goodName',
          title: '商品名称',
          type: 'string',
          width: 120,
          align: 'left',
          hidden: false,
          require: true,
        },
        {
          field: 'goodCode',
          title: '商品编码',
          type: 'string',
          width: 120,
          align: 'left',
          hidden: false,
          require: true,
        },
        {
          field: 'hotel_ID',
          title: '酒店id',
          type: 'string',
          width: 120,
          align: 'left',
          hidden: true,
        },
        {
          field: 'price',
          title: '平摊价',
          type: 'decimal',
          width: 90,
          align: 'left',
          sortable: true,
          hidden: false,
          edit: { type: 'decimal', required: true },
        },
        {
          field: 'number',
          title: '数量',
          type: 'int',
          width: 120,
          align: 'left',
          hidden: false,
          edit: { type: 'number' },
        },
      ],
      ActivityTypeStatus: false,
      RechargeTypeStatus: false,
      title: '新建',
      formFields1: {
        c_name: '',
        start_time: '',
        end_time: '',
        timeContainer: [],
        timeContainers: [],
        c_type: '',
        distributionid: '',
        membertype: [],
        isShow: 1,
        isPublic: 0,
        isShare: 0,
        memberlevels: [],
        application_endtime: '',
        application_endtime: '',
        phone: '',
        address: '',
        pics: [],
        picid: [],
        fromId: '',
        activitysort: '',
        // latitudelongitude: ""
      },
      formRules1: [
        [
          {
            title: '分销商',
            field: 'distributionid',
            type: 'select',
            dataKey: 'distributorList',
            data: [],
            required: true,
            disabled: false,
          },
          {
            title: '是否启用',
            field: 'isShow',
            type: 'switch',
            required: true,
            disabled: false,
          },
        ],
        [
          {
            title: '活动类型',
            field: 'c_type',
            type: 'select',
            // dataKey: "mall_activity_type",
            data: [],
            required: true,
            disabled: false,
          },

          {
            title: '活动名称',
            field: 'c_name',
            type: 'text',
            required: true,
            disabled: false,
          },
        ],

        [
          {
            title: '活动时间',
            field: 'timeContainer',
            type: 'datetime',
            required: true,
            range: true,
            disabled: false,
          },
          {
            title: '报名时间',
            field: 'timeContainers',
            type: 'datetime',
            range: true,
            disabled: false,
            required: true,
          },
        ],
        [
          {
            title: '封面图',
            maxSize: 1,
            field: 'picid',
            colSize: 3,
            type: 'imgupgrade',
            maxFile: 1,
            multiple: true,
            img: true,
            url: '/api/mall_activity/Upload',
          },
          {
            title: '轮播图',
            maxSize: 1,
            field: 'pics',
            colSize: 8,
            type: 'imgupgrade',
            maxFile: 5,
            multiple: true,
            url: '/api/mall_activity/Upload',
          },
        ],
        [
          {
            title: '排序',
            field: 'activitysort',
            type: 'text',
          },
        ],
        [
          {
            title: '报名人数',
            field: 'groupsize',
            type: 'text',
            cont: '人',
            hidden: false,
          },
          // {
          //   title: "会员类型",
          //   field: "membertype",
          //   type: "selectList",
          //   dataKey: "Member_Type",
          //   data: [],
          //   hidden: true
          // },
          {
            title: '电话',
            field: 'phone',
            type: 'text',
            hidden: false,
          },
          // {
          //   title: "会员等级",
          //   field: "memberlevels",
          //   type: "selectList",
          //   dataKey: "",
          //   data: [],
          //   // { key: 29, value: "111" }
          //   hidden: false
          // }
        ],
        [
          {
            title: '详情介绍',
            field: 'fromId',
            type: 'select',
            dataKey: 'mall_test',
            data: [],
          },
        ],
        [
          {
            title: '是否公开',
            field: 'isPublic',
            type: 'switch',
            required: true,
            disabled: false,
            colSize: 2,
          },
          {
            title: '是否分享',
            field: 'isShare',
            type: 'switch',
            required: true,
            disabled: false,
            colSize: 2,
          },
        ],
      ],
      formFields2: {
        sellingRulesid: '',
        refundrulesid: '',
        verificationrulesid: '',
        c_remark: '',
        latitudelongitude: '',
        address: '',
      },
      formRules2: [
        [
          {
            title: '售卖规则',
            required: true,
            field: 'sellingRulesid',
            type: 'select',
            dataKey: '',
            data: [],
            disabled: false,
          },
          {
            title: '退改规则',
            required: true,
            field: 'refundrulesid',
            type: 'select',
            dataKey: '',
            data: [],
            disabled: false,
          },
        ],
        [
          {
            title: '核销规则',
            required: true,
            field: 'verificationrulesid',
            type: 'select',
            dataKey: '',
            data: [],
            disabled: false,
          },
        ],
        [
          {
            title: '地址名称',
            required: true,
            field: 'address',
            type: 'text',
          },
          {
            dataKey: '',
            title: '位置',
            field: 'latitudelongitude',
            remote: true,
            data: [],
            placeholder: '输入位置关键字段搜索',
            type: 'select',
          },
        ],
        [
          {
            title: '活动说明',
            field: 'c_remark',
            type: 'textarea',
            disabled: false,
            colSize: 12,
          },
        ],
      ],
      formFields3: {
        groupsize: '',
        purchaseseparately: '',
        virtualclustering: '',
        maximumvirtualnumber: '',
        attendancecarddisplay: '',
        groupeffectivetime: '',
      },
      formRules3: [
        [
          {
            title: '成团人数',
            field: 'groupsize',
            type: 'textAppend',
            cont: '人',
            disabled: false,
          },
          {
            title: '单独购买',
            field: 'purchaseseparately',
            type: 'switch',
            disabled: false,
          },
        ],
        [
          {
            title: '虚拟成团',
            field: 'virtualclustering',
            type: 'switch',
          },
          {
            title: '最多虚拟人数',
            field: 'maximumvirtualnumber',
            type: 'number',
            disabled: false,
          },
        ],
        [
          {
            title: '参团卡显示',
            field: 'attendancecarddisplay',
            type: 'switch',
            disabled: false,
          },
          {
            title: '组团有效时间',
            field: 'groupeffectivetime',
            type: 'textAppend',
            cont: '小时',
            disabled: false,
          },
        ],
      ],
      formFields4: {
        preferentialtype: '',
        c_remark: '',
      },
      formRules4: [
        [
          {
            title: '优惠类型',
            field: 'preferentialtype',
            type: 'radio',
            data: [
              {
                value: '消费金额',
                key: '0',
              },
              {
                value: '购买件数',
                key: '1',
              },
            ],
            disabled: false,
          },
          {
            title: '活动说明',
            field: 'c_remark',
            type: 'text',
            disabled: false,
          },
        ],
      ],
      formlist: [],
      disabledformFields4: false,
      ZB: {},
      listType: '',
      columns: [
        {
          field: 'spare2',
          title: '活动档名称',
          type: 'text',
          width: 100,
          align: 'center',
          edit: { type: 'text', keep: true },
          fixed: 'left',
        },
        {
          field: 'name',
          title: '商品名称',
          type: 'string',
          width: 100,
          align: 'center',
        },

        {
          field: 'price',
          title: '价格',
          align: 'center',
          width: 50,
        },
        {
          field: 'activityPrice',
          title: '活动价格',
          align: 'center',
          width: 50,
          require: true,
          edit: { type: 'text', keep: true },
        },
        {
          field: 'c_id',
          title: 'c_id',
          align: 'center',
          width: 50,
          hidden: true,
        },
        {
          field: 'activityStock',
          title: '活动库存',
          type: 'string',
          width: 50,
          align: 'center',
          require: true,
          edit: { type: 'text', keep: true },
        },
        {
          title: '报名单',
          field: 'fromId',
          type: 'select',
          bind: { key: 'activity_form', data: [] },
          edit: { type: 'select', keep: true },
        },
        {
          field: 'D',
          title: '操作',
          type: 'string',
          width: 50,
          render: (h, { row, column, index }) => {
            return h(
              'div',
              {
                on: {
                  click: (e) => {
                    this.goodsListInfo.splice(index, 1)
                    if (this.title == '编辑') {
                      this.goodListDel.push(row.c_id)
                    }
                  },
                },
              },
              '删除'
            )
          },
        },
      ],
      columnsc: [
        {
          field: 'spare2',
          title: '活动档名称',
          type: 'text',
          width: 100,
          align: 'center',
          edit: { type: 'text', keep: true },
          fixed: 'left',
        },
        {
          field: 'name',
          title: '商品名称',
          type: 'string',
          width: 100,
          align: 'center',
        },

        {
          field: 'price',
          title: '价格',
          align: 'center',
          width: 50,
        },
        {
          field: 'activityPrice',
          title: '活动价格',
          align: 'center',
          width: 50,
        },
        {
          field: 'activityStock',
          title: '活动库存',
          type: 'string',
          width: 50,
          align: 'center',
        },
      ],
      relationshipInfo: [],
      goodsListInfo: [],
      buttonDisabled: false,
      goodsListInfo2: [],
      model2: false,
      columns2: [
        {
          field: 'pic_path',
          title: '商品图片',
          type: 'img',
          width: 100,
          align: 'center',
        },
        {
          field: 'name',
          title: '商品名称',
          type: 'string',
          width: 100,
          align: 'center',
        },
        {
          field: 'price',
          title: '价格',
          align: 'center',
          width: 50,
        },
      ],
      columns3: [
        {
          field: 'id',
          title: 'ID',
          type: 'string',
          width: 60,
          align: 'center',
        },
        {
          field: 'coupon_make_name',
          title: '券名称',
          type: 'string',
          width: 100,
          align: 'center',
        },
      ],
      columns4: [
        {
          field: 'coupon_make_name',
          title: '券名称',
          type: 'string',
          width: 100,
          align: 'center',
        },
        {
          field: 'CouponNum',
          title: '数量',
          type: 'string',
          width: 100,
          align: 'center',
          edit: { type: 'text', keep: true },
        },
      ],
      CodityClaifa: [],
      ticketTableData: [],
      name: '',
      defaultProps: {
        children: 'children',
        label: 'label',
      },
    }
  },
  watch: {
    model(v, n) {
      if (v) {
        this.updateDis()
      }
    },
    'formFields1.c_type': {
      handler(v, n) {
        switch (v) {
          case '0':
            this.ActivityTypeStatus = true
            this.RechargeTypeStatus = false
            break
          case '1':
            this.ActivityTypeStatus = true
            this.RechargeTypeStatus = false
            break
          case '2':
            this.ActivityTypeStatus = true
            this.RechargeTypeStatus = false
            if (this.title == '新建') {
              this.formlist = [
                {
                  fullPrice: '',
                  discount: '',
                },
              ]
            }

            this.listType = '优惠金额'
            break
          case '3':
            this.ActivityTypeStatus = true
            this.RechargeTypeStatus = false
            if (this.title == '新建') {
              this.formlist = [
                {
                  fullPrice: '',
                  discount: '',
                },
              ]
            }
            this.listType = '折扣'
            break
          case '5':
            this.rechargeGift.forEach((item) => {
              if (item.field == 'rechargeAmount') {
                item.hidden = false
              } else if (item.field == 'giftAmount') {
                item.hidden = false
              } else if (item.field == 'vouchersName') {
                item.hidden = false
              } else if (item.field == 'vouchersRemark') {
                item.hidden = false
              } else if (item.field == 'cardTemplate') {
                item.bind.data = this.kaAccount
                item.hidden = false
              } else if (item.field == 'cardList') {
                // item.bind.data=this.kaList
                item.hidden = false
              } else {
                item.hidden = true
              }
            })
            this.RechargeTypeStatus = true
            this.ActivityTypeStatus = false
            // console.log('充值赠送')

            break
          case '6':
            this.rechargeGift.forEach((item) => {
              if (item.field == 'discountAmount') {
                item.hidden = false
              } else if (item.field == 'discountPrice') {
                item.hidden = false
              } else if (item.field == 'vouchersName') {
                item.hidden = false
              } else if (item.field == 'vouchersRemark') {
                item.hidden = false
              } else if (item.field == 'cardTemplate') {
                item.bind.data = this.kaAccount
                item.hidden = false
              } else if (item.field == 'cardList') {
                item.hidden = false
              } else {
                item.hidden = true
              }
            })
            console.log('充值折扣')
            this.ActivityTypeStatus = false
            this.RechargeTypeStatus = true
            break
          case '7':
            this.rechargeGift.forEach((item) => {
              if (item.field == 'rechargeAmount') {
                item.hidden = false
              } else if (item.field == 'vouchersNum') {
                item.hidden = false
              } else if (item.field == 'Render') {
                item.hidden = false
              } else if (item.field == 'vouchersName') {
                item.hidden = false
              } else if (item.field == 'vouchersRemark') {
                item.hidden = false
              } else if (item.field == 'cardTemplate') {
                item.bind.data = this.kaAccount
                item.hidden = false
              } else if (item.field == 'cardList') {
                item.bind.data = this.kaList
                item.hidden = false
              } else {
                item.hidden = true
              }
            })
            this.RechargeTypeStatus = true
            this.ActivityTypeStatus = false
            // console.log('充值送券')
            break
          case '8':
            let isPublic = this.getOption('isPublic')
            let isShare = this.getOption('isShare')
            isPublic.hidden = false
            isShare.hidden = false
            this.RechargeTypeStatus = false
            this.ActivityTypeStatus = true
            // console.log('报名活动')
            break
        }
      },
      deep: true,
      immediate: true,
    },
    radio: {
      handler(v, n) {
        if (v == 1) {
          this.voucherPackageData = []
          this.getVoucherPackage()
        } else {
          this.voucherPackageData = []
          this.getVoucher()
        }
      },
      deep: true,
      immediate: true,
    },
  },
  created() {
    this.GetProductType()
    this.cardTemplate()
  },
  mounted() {

  },
  methods: {
    delRows() {
      let rows = this.$refs.table_one.getSelected()
        this.$refs.table_one.delRows()
      if (rows.length == 0){ return this.$Message.error('请选择要删除的行!')}else{
         rows.forEach((items)=>{
          items.children.forEach((item)=>{
          this.goodListDel.push(item.c_id)
          })
             })
      }
    },
    renderFunc(h, option) {
      return option.name.length > 8 ? (
        <el-tooltip effect="light" content={option.name} placement="top">
          <span>{option.name}</span>
        </el-tooltip>
      ) : (
        <span>{option.name}</span>
      )
    },
    getRenderOperate() {
      return (h, { row, column, index }) => {
        return h('div', { style: {} }, [
          h(
            'a',
            {
              props: {},
              style: { 'border-bottom': '1px solid' },
              on: {
                click: (e) => {
                  this.buttonDisabled = false
                  this.voucherPackageData = []
                  this.elementIdex = row.elementIdex
                  this.box2 = true
                  this.NameListDG = ''
                  this.NameList = []
                  if (row.children == undefined) {
                    this.goodsListInfo = []
                    return false
                  }
                  if (row.children != undefined) {
                    this.goodsListInfo = row.children
                  }
                },
              },
            },
            '编辑  '
          ),
        ])
      }
    },
    loadBefore(params, callback) {
      //设置查询 条件
      var _row
      //获取主表选中的行
      this.$emit('parentCall', ($vue) => {
        var rows = $vue.getSelectRows()
        if (rows.length) {
          _row = rows[0]
        }
      })
      if (!_row) {
        //取消选中，清空明细
        return (this.$refs.tableList.rowData.length = 0)
        //  return this.$Message.error("请选中主表行数据");
      }
      //设置查询条件，用主表id加载明细表数据(如果是自己定义的接口，这里条件自己处理)
      params.value = _row.Order_Id
      //设置排序字段(如果是自己定义的接口，排序字段不一定填写)
      if (!params.sort) {
        params.sort = 'CreateDate'
      }
      return callback(true)
    },
    getOption(field) {
      let option
      this.formRules1.forEach((x) => {
        x.forEach((item) => {
          if (item.field == field) {
            option = item
          }
        })
      })
      return option
    },
    getOption2(field) {
      let option
      this.formRules2.forEach((x) => {
        x.forEach((item) => {
          if (item.field == field) {
            option = item
          }
        })
      })
      return option
    },
    checkchange() {
      let v = this.$refs.tree.getCheckedNodes()
      console.log(v, 'v')
      let checkArr = []
      if (v.length != 0) {
        v.forEach((item) => {
          checkArr.push(item.typeCode)
        })
        this.NameList = []
        this.http.post('api/Mall_good/GetMallProduct', { tpyeid: checkArr.toString() }).then((res) => {
          res.data.forEach((i) => {
            let obj = {
              key: i.id,
              value: i.name,
            }
            this.NameList.push(obj)
          })
        })
      }
    },
    changeNameListDG(val) {
      // console.log(val, 'val')
      this.http.post('api/Mall_good/GetMallGoodList', { productid: val }).then((res) => {
        // console.log(res, '产品下的商品')
        this.goodsListInfo2 = res.data
        this.$nextTick(() => {
          this.goodsListInfo.forEach((item) => {
            this.$refs.xztable.$refs.table.toggleRowSelection(
              this.goodsListInfo2.find((tx) => {
                return tx.goods_id == item.goods_id
              }),
              true
            )
          })
        })
      })
    },
    updateDis() {
      let formRulesNew = [...this.formRules1, ...this.formRules2, ...this.formRules3, ...this.formRules4]
      if (this.title == '查看') {
        formRulesNew.forEach((i) => {
          i.forEach((j) => {
            j.disabled = true
          })
        })
        this.disabledformFields4 = true
        this.buttonDisabled = true
        this.columnsc.forEach((i) => {
          if (i.field == 'activityStock') {
            i.edit = null
          } else if (i.field == 'activityPrice') {
            i.edit = null
          }
        })
      } else {
        if (this.title == '编辑') {
          this.buttonDisabled = true
          this.columnsc.forEach((i) => {
            if (i.field == 'activityStock') {
              i.edit = { type: 'text', keep: true }
            } else if (i.field == 'activityPrice') {
              i.edit = { type: 'text', keep: true }
            }
          })
          if (new Date().getTime() - new Date(this.formFields1.start_time).getTime() > 0) {
            // 进行中
            formRulesNew.forEach((i) => {
              i.forEach((j) => {
                switch (j.field) {
                  case 'distributionid':
                    j.disabled = true
                    break
                  case 'c_type':
                    j.disabled = true
                    break
                  case 'c_name':
                    j.disabled = true
                    break
                  default:
                    j.disabled = false
                    break
                }
              })
            })
            this.disabledformFields4 = true
          } else {
            // 未开始
            this.disabledformFields4 = false
            formRulesNew.forEach((i) => {
              i.forEach((j) => {
                j.disabled = false
              })
            })
          }
        } else {
          this.buttonDisabled = false
          this.disabledformFields4 = false
          this.formlist = [
            {
              fullPrice: '',
              discount: '',
            },
          ]
          formRulesNew.forEach((i) => {
            i.forEach((j) => {
              j.disabled = false
            })
          })
          this.goodsListInfo = []
          this.goodsListInfo2 = []
        }
      }
    },
    btnClick(v, b) {
      if (v == 0) {
        this.formlist.splice(b, 1)
      } else {
        this.formlist.push({
          fullPrice: '',
          discount: '',
        })
      }
    },
    rowClick({ row, column, event }) {
      this.$refs.octable.$refs.table.toggleRowSelection(row)
    },
    addsp() {
      this.model2 = true
      this.name = ''
      this. NameList= [],
      this. NameListDG= ''
      this.goodsListInfo2=[]
      if (this.title == '新建') {
        if (this.goodsListInfo.length == 0) {
          this.$refs.tree.setCheckedNodes([])
        }
      }
    },
    addqList() {
      this.box3 = true
    },
    submit2() {
      // this.goodsListInfo = this.$refs.xztable.getSelected()
      console.log(this.$refs.xztable.getSelected(),"this.$refs.xztable.getSelected()")
      let getSelectedTable=[]
      this.$refs.xztable.getSelected().forEach((item,index,arr)=>{
        if(item==undefined){
          console.log("123")
          getSelectedTable= this.$refs.xztable.getSelected().splice(1)
        }else{
          getSelectedTable= this.$refs.xztable.getSelected()
        }
      })
      this.$nextTick(()=>{
        this.goodsListInfo.push(...getSelectedTable)
      })
      this.model2 = false
    },
    setprefreialtems(e) {
      if (e) {
        this.formlist = e
      } else {
        this.formlist = [
          {
            fullPrice: '',
            discount: '',
          },
        ]
      }
    },
    GetProductType() {
      let sellingRulesid2 = this.getOption2('sellingRulesid')
      let refundrulesid2 = this.getOption2('refundrulesid')
      let verificationrulesid2 = this.getOption2('verificationrulesid')
      let c_type = this.getOption('c_type')
      this.http
        .post('/api/Dictionary/GetVueDictionary', [
          'mall_sellingrules',
          'Mall_refundrules',
          'mall_verificationrules',
          'Member_Type',
          'mall_activity_type',
        ])
        .then((res) => {
          if (res) {
            res.forEach((i) => {
              switch (i.dicNo) {
                case 'mall_sellingrules':
                  sellingRulesid2.data = i.data
                  break
                case 'Mall_refundrules':
                  refundrulesid2.data = i.data
                  break
                case 'mall_verificationrules':
                  verificationrulesid2.data = i.data
                  break
                case 'mall_activity_type':
                  let arr = []
                  i.data.forEach((item) => {
                    if (item.value == '报名活动') {
                      arr.push(item)
                    }
                    c_type.data = arr
                  })
                  break
              }
            })
          }
        })
      this.http.get('api/producttypes/GetProductType').then((res) => {
        function arrReduce(someArr) {
          for (let i = 0; i < someArr.length; i++) {
            if (someArr[i].children) {
              arrReduce(someArr[i].children)
              someArr[i].label = someArr[i].typeName
              someArr[i].value = someArr[i].id
            } else {
              someArr[i].label = someArr[i].typeName
              someArr[i].value = someArr[i].id
            }
          }
        }
        arrReduce(res.data)
        this.CodityClaifa = res.data
      })
    },
    submit1() {
      this.$refs.formRules1.validate(() => {
        this.$refs.myform2.validate(()=>{
        let sku = this.$refs.octable.tableData

        let status = sku.some((i) => {
          if (i.activityPrice == undefined || i.activityStock == undefined || i.activityPrice == '' || i.activityStock == '') {
            return false
          } else {
            return true
          }
        })
        if (status||
          this.formFields1.c_type == '5' ||
          this.formFields1.c_type == '6' ||
          this.formFields1.c_type == '7' ||
          this.formFields1.c_type == 8
        ) {
          this.skuList = []
          this.tableData.forEach((item) => {
            if(item.children!=undefined){
            item.children.forEach((t) => {
              t.activity_session = item.activity_session
              t.activity_session_date = item.activity_session_date
              t.c_activityid = this.ZB.c_id
              t.merchantCode = this.ZB.merchantCode
              t.merchantName = this.ZB.merchantName
              t.activityNowStock = t.activityStock
              t.membertypes = t.membertype
              this.skuList.push(t)
            })}
            // else{
              // this.$Message.error('场次下必须有活动商品')
              // return false
            // }
          })
          let params = {
            mainData: {},
            detailData: this.skuList,
            delKeys:this.goodListDel.length==0?null:Array.from(new Set(this.goodListDel))
          }
          this.formFields1.start_time = this.formFields1.timeContainer[0]
          this.formFields1.end_time = this.formFields1.timeContainer[1]
          this.formFields1.application_starttime = this.formFields1.timeContainers[0]
          this.formFields1.application_endtime = this.formFields1.timeContainers[1]
          params.mainData = {
            ...this.formFields1,
            ...this.formFields2,
          }
          if (this.title == '新建') {
            this.$refs.formRules1.validate(() => {
              this.http.post('/api/mall_activity/AddActivityApplication', params).then((res) => {
              if (res.status) {
                this.model = false
                this.$Message.success('保存成功!')
                this.$store.getters.data().viewPageTest.refresh()
              } else {
                this.$Message.error(res.message)
              }
            })
      });
          } else {
            params.mainData.c_id = this.ZB.c_id
            this.http.post('/api/mall_activity/UpdateApplicationActivity', params).then((res) => {
              if (res.status) {
                this.model = false
                this.$Message.success('保存成功!')
                this.$store.getters.data().viewPageTest.refresh()
              } else {
                this.$Message.error(res.message)
              }
            })
          }
        } else {
          this.$Message.error('请输入活动价格和活动商品数量')
        }
      })
    })
    },
    // 获取券或者券包下拉
    getVoucherPackage() {
      let params = {
        order: 'desc',
        page: 1,
        rows: 100000000000000,
        sort: 'id',
        wheres: '[{"name":"coupon_type","value":"1","displayType":"text"}]',
      }
      this.http.post('/api/MebcouponMake/getPageData', params).then((res) => {
        this.voucherPackageList = []
        res.rows.forEach((i) => {
          let obj = {
            key: i.coupon_makeid,
            value: i.coupon_name,
          }
          this.voucherPackageList.push(obj)
        })
      })
    },
    getVoucher() {
      let params = {
        order: 'desc',
        page: 1,
        rows: 100000000000000,
        sort: 'id',
        wheres: '[]',
      }
      this.http.post('/api/MebCouponhis/getPageData', params).then((res) => {
        this.voucherPackageList = []
        this.voucherPackageList = res.rows
      })
    },
    voucherChild() {
      this.box2 = false
      this.goodsListInfo.forEach((item) => {
        if (!item.hasOwnProperty('membertype')) {
          item.membertype = ''
        }
        if (!item.hasOwnProperty('memberlevels')) {
          item.memberlevels = ''
        }
        if (!item.hasOwnProperty('fromId')) {
          item.fromId = ''
        }
        if (!item.hasOwnProperty('c_id')) {
          item.c_id = ''
        }
      })
      this.tableData.forEach((item) => {
        if (item.elementIdex == this.elementIdex) {
          item.children = []
          item.children = this.goodsListInfo
        }
      })
      this.goodsListInfo2 = []
    },
    isVoucher() {
      this.tableData.forEach((item) => {
        if (item.elementIdex == this.elementIdex) {
          item.children = {
            radio: this.radio,
            voucherPackageData: this.voucherPackageData,
            voucherPackageDataName: this.voucherPackageDataName,
          }
        }
      })
    },
    isVouchers() {
      this.tableData.forEach((item) => {
        if (item.elementIdex == this.elementIdex) {
          item.children = {
            radio: this.radio,
            voucherPackageListGL: this.voucherPackageListGL,
          }
        }
      })
    },
    voucherChilds() {
      this.box3 = false
      this.voucherPackageListGL = this.$refs.Qtable.getSelected()
    },
    changeselect(val) {
      console.log(val, 'this.voucherPackageDataName')
      if (this.radio == '1') {
        this.voucherPackageDataName = []
        this.voucherPackageList.forEach((item) => {
          for (let i = 0; i < val.length; i++) {
            if (item.key == val[i]) {
              let obj = {
                key: item.key,
                value: item.value,
              }
              this.voucherPackageDataName.push(obj)
            }
          }
        })
      } else {
        this.voucherPackageDataName = []
        this.voucherPackageList.forEach((item) => {
          for (let i = 0; i < val.length; i++) {
            if (item.key == val[i]) {
              let obj = {
                key: item.key,
                value: item.value,
              }
              this.voucherPackageDataName.push(obj)
            }
          }
        })
      }
    },
    // 卡模版
    cardTemplate() {
      let params = {
        page: 1,
        rows: 5000000000,
        sort: 'id',
        order: 'desc',
        wheres: '[{"name":"basetype","value":"1","displayType":"select"}]',
      }
      // 卡模板
      this.http.post('/api/MebCardtype/CardGetPageData', params).then((res) => {
        this.kaAccount = res.rows.map((i) => {
          return {
            key: i.cardtypeid.toString(),
            value: i.cardtypename,
          }
        })
      })

    },
    // 卡列表
    cardList(key) {
      let params = {
        page: 1,
        rows: 500,
        sort: 'id',
        order: 'desc',
        wheres: `[{\"name\":\"card_type\",\"value\":\"${key}\",\"displayType\":\"text\"}]`,
      }
      this.http.post('/api/member_card_make/CardMakeGetPageData', params).then((res) => {
        if (res.rows != null && res.rows.length != 0) {
          this.kaList = res.rows.map((i) => {
            return {
              key: i.card_batch,
              // value: i.note
              value: i.card_batch,
            }
          })
          this.rechargeGift.forEach((item) => {
            if (item.field == 'cardList') {
              item.bind.data = this.kaList
            }
          })
        } else {
        }
      })
    },
  },
}
export default vueParam
</script>
<style lang="less">
.formFields5 {
  .el-form-item__label {
    color: #939394;
    font-size: 12px;
  }
  .yhtjint {
    font-size: 12px;
  }
  .el-input {
    width: 70px;
  }
}
</style>
<style lang="less" scoped>
.SPXZ {
  display: flex;
  justify-content: space-between;
  .volTable {
    width: 60%;
  }
  .el-tree {
    width: 40%;
    height: 450px;
    overflow-y: auto;
  }
}
.tjBut {
  margin: 10px;
}
.boxButton {
  margin-bottom: 10px;
  margin-top: 10px;
}
.boxButtons {
  width: 100%;
  margin-bottom: 10px;
  margin-top: 10px;
}
.searchDiv {
  display: flex;
  justify-content: space-around;
  .int {
    margin-left: 10px;
  }
  .el-button {
    height: 40px;
    margin-left: 10px;
  }
}
</style>
